/*
 **                Copyright 2012, MARVELL SEMICONDUCTOR, LTD.
 ** THIS CODE CONTAINS CONFIDENTIAL INFORMATION OF MARVELL.
 ** NO RIGHTS ARE GRANTED HEREIN UNDER ANY PATENT, MASK WORK RIGHT OR COPYRIGHT
 ** OF MARVELL OR ANY THIRD PARTY. MARVELL RESERVES THE RIGHT AT ITS SOLE
 ** DISCRETION TO REQUEST THAT THIS CODE BE IMMEDIATELY RETURNED TO MARVELL.
 ** THIS CODE IS PROVIDED "AS IS". MARVELL MAKES NO WARRANTIES, EXPRESSED,
 ** IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, COMPLETENESS OR PERFORMANCE.
 **
 ** MARVELL COMPRISES MARVELL TECHNOLOGY GROUP LTD. (MTGL) AND ITS SUBSIDIARIES,
 ** MARVELL INTERNATIONAL LTD. (MIL), MARVELL TECHNOLOGY, INC. (MTI), MARVELL
 ** SEMICONDUCTOR, INC. (MSI), MARVELL ASIA PTE LTD. (MAPL), MARVELL JAPAN K.K.
 ** (MJKK), MARVELL ISRAEL LTD. (MSIL).
 */

package com.android.settings.bluetooth;

import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public final class BluetoothAutoPairConnReceiver extends BroadcastReceiver {
    private static final String TAG = "BluetoothAutoPairConnReceiver";

    private static final String ACTION_AUTO_PAIR_CONN = "com.marvell.bluetooth.AUTO_PAIR_CONN";
        //hisense add
    private static final String ACTION_AUTO_PAIR_CONN_COMPLETED =
            "com.marvell.bluetooth.AUTO_PAIR_CONN_COMPLETED";

    private static final String ACTION_AUTO_PAIR_CONN_SKIP =
                "com.marvell.bluetooth.AUTO_PAIR_CONN_SKIP";
    private static final String ACTION_CANCEL_AUTO_PAIR_CONN =
            "com.marvell.bluetooth.CANCEL_AUTO_PAIR_CONN";
    private static final String EXTRA_BT_RC_NAME = "BT_RC_NAME";

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        Log.i(TAG, "onReceive " + action);

        if (action.equals(ACTION_AUTO_PAIR_CONN)) {
            String btRcName = intent.getStringExtra(EXTRA_BT_RC_NAME);
            Log.i(TAG, "onReceive ACTION_AUTO_PAIR_CONN " + ACTION_AUTO_PAIR_CONN +
                    " btRcName = " + btRcName);
            if (null != btRcName) {
                BluetoothAutoPairConnManager autoPairConnManager =
                        BluetoothAutoPairConnManager.createInstance(context);
                autoPairConnManager.requestAutoPairConn(btRcName);
            } else {
                Log.e(TAG, "onReceive btRcName should not be null!!");
            }
        } else if (action.equals(ACTION_CANCEL_AUTO_PAIR_CONN)) {
            Log.i(TAG, "onReceive ACTION_CANCEL_AUTO_PAIR_CONN " + ACTION_CANCEL_AUTO_PAIR_CONN);
            BluetoothAutoPairConnManager autoPairConnManager =
                    BluetoothAutoPairConnManager.getInstance();
            if (null != autoPairConnManager) {
                autoPairConnManager.notifyCancelAutoPairConn();
            }
        } else if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
            int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
            Log.i(TAG, "onReceive BluetoothAdapter.ACTION_STATE_CHANGED state = " + state);
            BluetoothAutoPairConnManager autoPairConnManager =
                    BluetoothAutoPairConnManager.getInstance();
            if (null != autoPairConnManager) {
                autoPairConnManager.notifyBTStateChanged(state);
            }
        }else if(action.equals(ACTION_AUTO_PAIR_CONN_SKIP))
        {
        		BluetoothAutoPairConnManager autoPairConnManager =
                    BluetoothAutoPairConnManager.getInstance();
            if (null != autoPairConnManager) {
                autoPairConnManager.setStateToSkip();
                autoPairConnManager.notifyExit();
            }
        }else if(action.equals(ACTION_AUTO_PAIR_CONN_COMPLETED))
        {
            BluetoothAutoPairConnManager autoPairConnManager =
                    BluetoothAutoPairConnManager.getInstance();
            if (null != autoPairConnManager) {
                autoPairConnManager.notifyCancelAutoPairConn();
                
            }
        }
    }
}
